index.html.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <ShopPageHead></ShopPageHead>
  3. <main class="index_main" id="all_vue">
  4. <div class="shop_banner">
  5. <a class="shop_banner_a" href="" title="">
  6. <img class="shop_banner_img" src="@/public/img/6.png" title="" alt="">
  7. </a>
  8. </div>
  9. <!--子菜单和地区选择-->
  10. <ShopSubMenu2></ShopSubMenu2>
  11. <!-- 地区选择 -->
  12. <div class="categ_crumb_box clearfix_2">
  13. <!-- 当前位置 -->
  14. <div class="categ_crumb_left">
  15. <a class="categ_crumb_left_a" title=""> 当前位置: </a>
  16. <NuxtLink
  17. :to="`/xiangcunshangcheng/index.html`"
  18. class="categ_crumb_left_a"
  19. >
  20. 乡村商城
  21. </NuxtLink>
  22. &gt;
  23. <span class="categ_crumb_left_text">{{name}}</span>
  24. </div>
  25. <!-- 当前位置 -->
  26. <!-- 当前商品所在地 -->
  27. <div class="categ_crumb_right clearfix" v-if="cityList.length > 0">
  28. <div class="categ_crumb_right_text">当前商品所在地:</div>
  29. <div class="categ_crumb_right_text hand">{{cityName}}</div>
  30. <div class="categ_crumb_right_btn back100 hand" @click="btn_if_categ_crumb_panel_fun" tabindex="1"
  31. @blur="categ_crumb_panel_btn_blur_fun">
  32. </div>
  33. </div>
  34. <!-- 当前商品所在地 -->
  35. <div class="categ_crumb_panel" v-show="if_categ_crumb_panel" tabindex="0"
  36. @click="categ_crumb_panel_focus_fun" @blur="categ_crumb_panel_blur_fun">
  37. <h4 class="categ_crumb_panel_h4">您可以选择以下详细地区</h4>
  38. <div class="categ_crumb_panel_btn_box clearfix">
  39. <span
  40. class="categ_crumb_panel_btn hand"
  41. :class="{ categ_crumb_panel_btn_only: item.id == chooseCityId }"
  42. v-for="item in cityList"
  43. @click="chooseCity(item.id)"
  44. >
  45. {{ item.name }}
  46. </span>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 您可以选择以下详细地区 -->
  51. <div class="categ_grey_box clearfix" v-if="secondNav.length > 0">
  52. <div class="categ_grey_head">您可以选择以下详细分类:</div>
  53. <div class="categ_grey_ul clearfix">
  54. <span
  55. :class="['categ_grey_btn hand', { 'categ_grey_btn_only': selectedSecondId == item.category_id }]"
  56. v-for="item in secondNav"
  57. @click="selectSecond(item)"
  58. >
  59. {{ item.alias }}
  60. </span>
  61. </div>
  62. </div>
  63. <!-- 您可以选择以下详细地区 -->
  64. <!-- 供应信息列表 -->
  65. <!-- <div class=" clearfix" v-show="choice_categ_num == 1"> -->
  66. <div class=" clearfix">
  67. <div class="categ_1_index clearfix">
  68. <div class="categ_head_box clearfix_2">
  69. <span class="categ_head_a">供应信息列表</span>
  70. <nuxt-link
  71. to="/xiangcunshangcheng/nongfuchanpin/gongying/list-1.html"
  72. class="categ_head_a_more"
  73. >
  74. 查看更多 &gt;
  75. </nuxt-link>
  76. </div>
  77. <div class="categ_table clearfix">
  78. <div class="categ_table_head_box">
  79. <div class="categ_table_td_1">产品图片</div>
  80. <div class="categ_table_td_2">供求信息/公司</div>
  81. <div class="categ_table_td_3">发布时间</div>
  82. <div class="categ_table_td_4">地区</div>
  83. </div>
  84. <ShopNoData v-if="pageDataType1.length == 0" :pagetype="'class'"></ShopNoData>
  85. <div class="categ_table_li" v-for="item in pageDataType1" :key="item.id">
  86. <NuxtLink
  87. :to="getShopPathDetail1(item)"
  88. class="categ_table_li_a"
  89. :title="item.name"
  90. >
  91. <div class="categ_table_td_1">
  92. <img class="categ_table_td_1_img" :src="item.imgurl" alt="item.name">
  93. </div>
  94. <div class="search_table_td_2 ">
  95. <div class="search_table_td_2_in clearfix">
  96. <div class="search_table_td_2_head dot1">
  97. {{ item.name }}
  98. </div>
  99. <div class="search_table_td_2_dot2 dot2">
  100. {{ item.description }}
  101. </div>
  102. </div>
  103. </div>
  104. <div class="categ_table_td_3">{{getTime(item.created_at, 'year', 1)}}</div>
  105. <div class="categ_table_td_4 dot1">{{item.city_name}}</div>
  106. </NuxtLink>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <div class=" clearfix">
  112. <div class="categ_1_index clearfix">
  113. <div class="categ_head_box clearfix_2">
  114. <span class="categ_head_a">求购信息列表</span>
  115. <nuxt-link
  116. to="/xiangcunshangcheng/nongfuchanpin/qiugou/list-1.html"
  117. class="categ_head_a_more"
  118. >
  119. 查看更多 &gt;
  120. </nuxt-link>
  121. </div>
  122. <div class="categ_table clearfix">
  123. <div class="categ_table_head_box">
  124. <div class="categ_table_td_1">产品图片</div>
  125. <div class="categ_table_td_2">供求信息/公司</div>
  126. <div class="categ_table_td_3">发布时间</div>
  127. <div class="categ_table_td_4">地区</div>
  128. </div>
  129. <ShopNoData v-if="pageDataType2.length == 0" :pagetype="'class'"></ShopNoData>
  130. <div class="categ_table_li" v-for="item in pageDataType2" :key="item.id">
  131. <NuxtLink
  132. :to="getShopPathDetail1(item)"
  133. class="categ_table_li_a"
  134. :title="item.name"
  135. >
  136. <div class="categ_table_td_1">
  137. <img class="categ_table_td_1_img" :src="item.imgurl" alt="item.name">
  138. </div>
  139. <div class="search_table_td_2 ">
  140. <div class="search_table_td_2_in clearfix">
  141. <div class="search_table_td_2_head dot1">
  142. {{ item.name }}
  143. </div>
  144. <div class="search_table_td_2_dot2 dot2">
  145. {{ item.description }}
  146. </div>
  147. </div>
  148. </div>
  149. <div class="categ_table_td_3">{{getTime(item.created_at, 'year', 1)}}</div>
  150. <div class="categ_table_td_4 dot1">{{item.city_name}}</div>
  151. </NuxtLink>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. <ShopHotNews></ShopHotNews>
  157. </main>
  158. <!-- 页面底部 -->
  159. <HomeFoot></HomeFoot>
  160. </template>
  161. <script setup>
  162. //1.页面必备方法 start ---------------------------------------->
  163. import { ref, onMounted,watch } from 'vue'
  164. import { ElMessage } from 'element-plus'
  165. //1.页面必备方法 end ---------------------------------------->
  166. //2.页面路径 start ---------------------------------------->
  167. //2.1 获得页面数据id
  168. const route = useRoute();
  169. const router = useRouter()
  170. let articleId = 0; //把路径转换为数据id
  171. const targetSegment = getRoutePath(2);//返回第二层的路径id
  172. //通过导航路径反向查询导航id
  173. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  174. method: 'GET',
  175. query: {
  176. 'pinyin': targetSegment,
  177. },
  178. });
  179. if(getRouteId.code == 200){
  180. articleId = getRouteId.data.category_id
  181. }else{
  182. console.log("错误位置:获得页面路径")
  183. }
  184. //2.2 生成面包屑导航
  185. const name = ref('') //当前频道名称
  186. let getPageName = async () => {
  187. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  188. method: 'GET',
  189. query: {
  190. 'catid': articleId
  191. },
  192. });
  193. if (pageName.code == 200) {
  194. name.value = pageName.data.alias
  195. } else {
  196. console.log("错误位置:获取当前频道名称", pageName.message)
  197. }
  198. }
  199. getPageName();
  200. //2.3 获得子栏目列表
  201. const secondNav = ref([]);
  202. const selectedSecondId = ref(route.query.catid);//当前选中了哪个子导航
  203. let getSecondNav = async () => {
  204. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  205. method: 'GET',
  206. query: {
  207. 'placeid': 1,
  208. 'pid': articleId,
  209. 'num': 50,
  210. },
  211. });
  212. if (listData.code == 200) {
  213. secondNav.value = listData.data
  214. } else {
  215. console.log("错误位置:获得子级栏目列表")
  216. }
  217. }
  218. getSecondNav();
  219. //2.4 获得cityid
  220. const cityId = ref(route.query.cityid)
  221. //2.页面路径 end ---------------------------------------->
  222. //3.选择商品所在地 start ---------------------------------------->
  223. //您可以选择以下详细分类:
  224. const choice_categ_num = ref(1)
  225. // 您可以选择以下详细地区=btn
  226. const if_categ_crumb_panel_btn_num = ref(0)
  227. const if_categ_crumb_panel = ref(false)// 当前商品所在地下拉板
  228. const if_categ_crumb_panel_click = ref(false)// //判断是否点击在下拉板内
  229. const btn_if_categ_crumb_panel_fun = () => {//点击下拉btn
  230. if_categ_crumb_panel.value = !if_categ_crumb_panel.value
  231. }
  232. const categ_crumb_panel_btn_blur_fun = () => {//btn失去焦点事件
  233. setTimeout(() => {//的延迟器
  234. if (if_categ_crumb_panel_click.value == true) {//判断鼠标是否点击下拉panel
  235. //点击在下拉panel内
  236. } else {//没点击在下拉panel内
  237. if_categ_crumb_panel.value = false
  238. }
  239. }, 100);
  240. }
  241. //点击下拉panel
  242. const categ_crumb_panel_focus_fun = () => {
  243. if_categ_crumb_panel_click.value = true
  244. if_categ_crumb_panel.value = true
  245. }
  246. //下拉panel失去焦点事件
  247. const categ_crumb_panel_blur_fun = () => {
  248. if_categ_crumb_panel_click.value = false
  249. if_categ_crumb_panel.value = false
  250. }
  251. //获得详细地址列表
  252. const cityName = ref('')
  253. const cityList = ref([])
  254. const chooseCityId = ref('')
  255. let getCityList = async (id) => {
  256. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  257. method: 'GET',
  258. query: {
  259. 'pid': id,
  260. },
  261. });
  262. console.log(id)
  263. console.log(shengData)
  264. if(shengData.code==200){
  265. cityList.value = shengData.data;
  266. cityName.value = shengData.data[0].pid_name;
  267. }else{
  268. ElMessage.error(shengData.message)
  269. }
  270. }
  271. //初始化的时候先获取一下城市列表
  272. if(cityId.value != undefined){
  273. getCityList(cityId.value);
  274. }
  275. //选择城市
  276. const chooseCity = (id) => {
  277. chooseCityId.value = id;
  278. router.replace({
  279. query: {
  280. ...route.query,
  281. select: id
  282. }
  283. })
  284. }
  285. //3.选择商品所在地 end ---------------------------------------->
  286. //4.搜索 start ---------------------------------------->
  287. //4.1 选择一个子导航
  288. const selectSecond = (item) => {
  289. //高亮显示当前选中的子导航
  290. selectedSecondId.value = item.category_id
  291. router.replace({
  292. query: { ...route.query, catid: item.category_id }
  293. })
  294. }
  295. const pageDataType1 = ref([]);//供应数据
  296. const pageDataType2 = ref([]);//求购数据
  297. const pageSearch = async () => {
  298. let params = {
  299. catid:"",//栏目id
  300. city_id:"",//城市id
  301. keyword:"",//搜索关键词 - 该页不需要
  302. page:1,
  303. pageSize:3,
  304. //type_id:1//1:供应 2:求购
  305. }
  306. if(selectedSecondId.value == undefined){
  307. params.catid = articleId
  308. }else{
  309. params.catid = parseFloat(selectedSecondId.value)
  310. }
  311. let routeCiteId = route.query.select;
  312. if(routeCiteId != undefined && routeCiteId != ''){
  313. params.city_id = parseFloat(routeCiteId)
  314. }else{
  315. if(cityId.value == undefined || cityId.value == '' || cityId.value == 'NaN'){
  316. //删除变量params中的city_id参数
  317. delete params.city_id
  318. }else{
  319. params.city_id = parseFloat(cityId.value)
  320. }
  321. }
  322. const pageData = await requestDataPromise('/web/getWebsiteshopList', {
  323. method: 'GET',
  324. query: params,
  325. });
  326. if (pageData.code == 200) {
  327. pageDataType1.value = pageData.data.type1;
  328. pageDataType2.value = pageData.data.type2;
  329. } else {
  330. console.log("错误位置:获得该页面数据失败!")
  331. }
  332. //开始请求数据
  333. console.log(params)
  334. console.log(pageData)
  335. }
  336. //页面初始化的时候调用一下搜索
  337. pageSearch();
  338. //每次路由一变化就重新请求数据
  339. watch(() => route.query.cityid, (newVal, oldVal) => {
  340. if(newVal != undefined){
  341. cityId.value = parseFloat(newVal)
  342. getCityList(newVal)
  343. }else{
  344. cityList.value = []
  345. }
  346. pageSearch()
  347. })
  348. watch(() => route.query.catid, (newVal, oldVal) => {
  349. pageSearch()
  350. })
  351. watch(() => route.query.select, (newVal, oldVal) => {
  352. if(newVal != undefined){
  353. pageSearch()
  354. }else{
  355. chooseCityId.value = '';
  356. pageSearch()
  357. }
  358. })
  359. //4.搜索 end ---------------------------------------->
  360. //5.广告 start ---------------------------------------->
  361. //获得所有广告
  362. let adImg1 = ref({})
  363. onMounted(async () => {
  364. const { $webUrl, $CwebUrl } = useNuxtApp();
  365. //从客户端启动广告
  366. //广告1
  367. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_shopcategory_0001`
  368. const responseAd1 = await fetch(url, {
  369. headers: {
  370. 'Content-Type': 'application/json',
  371. 'Userurl': $CwebUrl,
  372. 'Origin': $CwebUrl
  373. }
  374. });
  375. const resultAd1 = await responseAd1.json();
  376. adImg1.value = resultAd1.data[0];
  377. })
  378. //5.广告 end ---------------------------------------->
  379. </script>
  380. <style lang="less" scoped>
  381. @import '@/assets/css/shop/class.less';
  382. </style>